#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <curl/curl.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <sqlite3.h>
#include "cJSON.h"


// 回调函数，用于写入文件
// size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) 
// {
//     return fwrite(ptr, size, nmemb, stream);
// }



// int main() 
// {
//     const char *url = "http://192.168.8.116:63259/family.dat";
//     const char *output_filename = "family.dat";
//     FILE *output_file = fopen(output_filename, "wb");
//     if (!output_file) 
//     {
//         fprintf(stderr, "Error opening output file\n");
//         return EXIT_FAILURE;
//     }

//     CURL *curl = curl_easy_init();
//     if (curl) 
//     {
//         curl_easy_setopt(curl, CURLOPT_URL, url);
//         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
//         curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file);

//         CURLcode res = curl_easy_perform(curl);
//         if (res != CURLE_OK) 
//         {
//             fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
//             fclose(output_file);
//             curl_easy_cleanup(curl);
//             return EXIT_FAILURE;
//         }

//         curl_easy_cleanup(curl);
//         fclose(output_file);
//         printf("File downloaded successfully.\n");
//         return EXIT_SUCCESS;
//     } else 
//     {
//         fprintf(stderr, "Failed to initialize libcurl\n");
//         fclose(output_file);
//         return EXIT_FAILURE;
//     }
// }




// =======================================================================================================================================
// int base64_decode(const char *input, cJSON **root) 
// {
//     BIO *bio, *b64;

//     // 计算解码后数据的长度
//     int input_len = strlen(input);
//     int decode_len = (input_len + 2) / 4 * 3;
//     char *buffer = (char *)malloc(decode_len);

//     // 创建 BIO 对象
//     bio = BIO_new_mem_buf(input, input_len);
//     b64 = BIO_new(BIO_f_base64());
//     bio = BIO_push(b64, bio);

//     // 禁止换行符
//     BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);

//     // 读取数据
//     int len = BIO_read(bio, buffer, input_len);
//     BIO_free_all(bio);

//     // 解析数据到 cJSON 对象
//     *root = cJSON_Parse(buffer);

//     // 释放缓冲区
//     free(buffer);

//     return len;
// }

// int main() 
// {
//     const char *base64_str = "W3siZGlkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDBhYWJiY2MwMGU3ZmQiLCJkZXZuYW1lIjoi5oKf56m65rS+fuaciee6v+e9keWFsyIsInJvb20iOiLljLrln58xIiwiZGV2aWNldHlwZWZsYWciOjAsInBpZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDNhYWUwMDAwIiwiYWVza2V5IjpudWxsLCJ0ZXJtaW5hbGlkIjoxLCJpZ25vcmVmbGFnIjpmYWxzZSwidmVyc2lvbiI6IjQuMS4wLjAuMzEiLCJyb29tSWQiOjAsImV4dGVuZEluZm8iOiIifSx7ImRpZCI6IiIsInBpZCI6IiIsImRldmljZXR5cGVmbGFnIjowLCJibGVjYXRldG9yeSI6IkxJR0hUIiwic3BpZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDI5YTgwMDAwIiwiZGV2bmFtZSI6IuS8jeaYiuWuj+eahOW+ruazoueBryIsInJvb20iOiLljLrln58xIiwicm9vbUlkIjoxLCJibGV0b2tlbiI6IjFiMTEwZDAyIiwiaWdub3JlZmxhZyI6ZmFsc2UsInZlcnNpb24iOiI0LjQxLjAuNTM2ODc0MjU4LjU5IiwiZXh0ZW5kSW5mbyI6IiIsInNob3J0YWRkciI6IjI1NyIsInNkaWQiOiIwMDAwMDAwMDAwMDAwMDAwMDAwMGU4MTY1NmQwMjhmZCJ9XQ=="; // 需要解密的base64字符串
//     cJSON *root = NULL;

//     int decode_len = base64_decode(base64_str, &root);

//     if (root) {
//         // 在这里对 root 进行操作，例如打印、访问其中的数据等
//         printf("Decoded JSON:\n%s\n", cJSON_Print(root));

//         // 使用完毕后释放 cJSON 对象
//         cJSON_Delete(root);
//     } else {
//         printf("Failed to decode base64 string.\n");
//     }

//     return 0;
// }


void trim_leading_zeros(char *input, char *output) {
    while (*input == '0') {
        input++;
    }
    strcpy(output, input);
}


void main()
{
    char trimmed_spid[64];
    char spid[] = "00000000000000000000e81656d028fd";
    trim_leading_zeros(spid, trimmed_spid);
    printf("%s\n", trimmed_spid);
}
